import axios from 'axios';

// 创建axios实例，简化配置
const instance = axios.create({
  baseURL: 'http://localhost:5005/api',
  timeout: 10000
});

// 导出API方法
export default {
  getAllCustomers() {
    return instance.get('/customers');
  },
  
  getSalesStageStats() {
    return instance.get('/stats/sales-stages');
  },
  
  getPlatformStats() {
    return instance.get('/stats/platforms');
  },
  
  getFilteredCustomers(type, value) {
    return instance.get(`/customers/filter?type=${type}&value=${value}`);
  },
  
  getFilteredCustomersByStages(stages) {
    // 将阶段数组转换为查询字符串
    return instance.post('/customers/filter-stages', { stages });
  },
  
  // 添加搜索客户的方法
  searchCustomers(keyword) {
    return instance.get(`/customers/search?keyword=${encodeURIComponent(keyword)}`);
  },
  
  // 添加测试CORS的方法
  testCors() {
    return instance.get('/test-cors');
  },

  // 新增：获取每月新增客户数量
  getMonthlyCustomers() {
    return instance.get('/stats/monthly-customers');
  },

  // 按月份获取当月新增客户详情
  getCustomersByMonth(month) {
    return instance.get(`/customers/by-month?month=${month}`);
  }
}; 